<template>
  <div class="fu-channel">
    <el-row v-show="ordin">
      <fu-ordinary @updateShow="handleUpdateShowStatus"></fu-ordinary>
    </el-row>
    <el-row v-if="ordin">
      <el-col :span="23" :offset="1">
        <el-button type="primary" size="small" @click="handleClickOnSubmit(200)">通过并提交审核</el-button>
        <el-button type="danger" size="small" @click="handleClickOnSubmit(-200)">不通过</el-button>
      </el-col>
    </el-row>
    <!-- <el-row v-show="activity">
      <fu-activities @updateShow="handleUpdateShowStatus"></fu-activities>
    </el-row>
    <el-row v-if="activity">
      <el-col :span="23" :offset="1">
        <el-button type="primary" size="small" @click="handleClickActiviOnSubmit(200)">通过并提交审核</el-button>
        <el-button type="danger" size="small" @click="handleClickActiviOnSubmit(-200)">不通过</el-button>
      </el-col>
    </el-row> -->
  </div>
</template>

<script>
import { verfiryChannelFuValid, verfiryChannelFuActiviValid } from '@/api/shop'
import FuActivities from './components/fu-channel/activities'
import FuOrdinary from './components/fu-channel/ordinary'

export default {
  components: {
    FuActivities,
    FuOrdinary
  },
  data() {
    return {
      activity: false,
      ordin: false
    }
  },
  methods: {
    handleClickOnSubmit(status) {
      if (status === -200) {
        this.$msgbox({
          title: '拒绝原因',
          showInput: true,
          inputType: 'textarea',
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          showCancelButton: true
        }).then(({ value }) => {
          verfiryChannelFuValid(this.$route.query.id, status, value).then(res => {
            if (res.data.errorCode === 0) {
              this.$message.success(res.data.errorMsg)
              this.ordin = false
              this.handleUpdateStatus()
            } else {
              this.$message.error(res.data.errorMsg)
            }
          })
        }).catch(() => {
          return false
        })
      } else {
        verfiryChannelFuValid(this.$route.query.id, status).then(res => {
          if (res.data.errorCode === 0) {
            this.$message.success(res.data.errorMsg)
            this.ordin = false
            this.handleUpdateStatus()
          } else {
            this.$message.error(res.data.errorMsg)
          }
        })
      }
    },
    handleClickActiviOnSubmit(status) {
      if (status === -200) {
        this.$msgbox({
          title: '拒绝原因',
          showInput: true,
          inputType: 'textarea',
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          showCancelButton: true
        }).then(({ value }) => {
          verfiryChannelFuActiviValid(this.$route.query.id, status, value).then(res => {
            if (res.data.errorCode === 0) {
              this.$message.success(res.data.errorMsg)
              this.activity = false
              this.handleUpdateStatus()
            } else {
              this.$message.error(res.data.errorMsg)
            }
          })
        }).catch(() => {
          return false
        })
      } else {
        verfiryChannelFuActiviValid(this.$route.query.id, status).then(res => {
          if (res.data.errorCode === 0) {
            this.$message.success(res.data.errorMsg)
            this.activity = false
            this.handleUpdateStatus()
          } else {
            this.$message.error(res.data.errorMsg)
          }
        })
      }
    },
    handleUpdateShowStatus(arr) {
      const [type, state] = arr
      if (type === 'ordin') {
        this.ordin = state
      }
      if (type === 'activity') {
        this.activity = state
      }
    },
    handleUpdateStatus() {
      if (!this.activity && !this.ordin) {
        this.$emit('update')
      }
    }
  }
}
</script>
